/*
package com.ywh.auth;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTCreationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.apache.commons.codec.binary.Base64;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

public class Jwt {
    public static final String RSA_ALGORITHM = "RSA";

    public static void main(String[] args) throws Exception {
     */
/*   String token = "";
        try {
            Algorithm algorithm = Algorithm.HMAC256("secret");
            token = JWT.create()
                    .withIssuer("auth0")
                    .sign(algorithm);
        } catch (JWTCreationException exception) {
            //Invalid Signing configuration / Couldn't convert Claims.
        }
        System.out.println(token);*//*



        String token = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJIaFNzVTBOa0Y2UjNQa01ZcVB6ajJxcHpvVWRyZVpWUUo2YmlQd01LTTBZIn0.eyJqdGkiOiIyMGZlODBmZC01M2JiLTRiZjEtYmE5OC03ZmM4OGU3MjdkNGMiLCJleHAiOjE1NjU5NTIyNjEsIm5iZiI6MCwiaWF0IjoxNTY1OTUxOTYxLCJpc3MiOiJodHRwOi8vMTI3LjAuMC4xOjgwODAvYXV0aC9yZWFsbXMvc3ByaW5nLWFwaSIsImF1ZCI6InNwcmluZy1jbGllbnQiLCJzdWIiOiIzMjgxNzBkMy04OGI1LTQ0MGYtODU1Yy0wMGNkOTE2YzgzZmIiLCJ0eXAiOiJJRCIsImF6cCI6InNwcmluZy1jbGllbnQiLCJhdXRoX3RpbWUiOjE1NjU5NDk1NDIsInNlc3Npb25fc3RhdGUiOiJlYzUzNDRhZi1kMjRkLTQ5YjYtYmMxMS1hODNkZjdlNjlkM2QiLCJhY3IiOiIwIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ1c2VyIiwiZW1haWwiOiJ5a2FzYmRnQHFxLmNvbSJ9.ioasUZ_YOb1eSIK3bTCMySJB4alTXzCwPYj-Faxc4-jsPpcJh150x15BP0JJnS2Jm8itxCrrH8SvyliGl1TZt2cw1NpT7cTepcuujEytKmezMFXVMozyCEbKRR0JTF_mJyl1XQXTlAC_R3rCAVuHR3Lu4c9q59WXraWj68vqleLVCC6a9fc6U-B6uERxnh7C9y0b6-uDcdJTZME2HHhgS2AURWAFsb4VH3Pt9702-fPWgal47Xs5aXWPxwfKweq27l0eMP9_Q2C2XYtg0qvw5wFZDPVhW5zwmNCZkri4JCF2hkedYg2CGgpCUpUEAxhlg1EZU6PhsvfiFnsBD3DCsQ";

        RSAPublicKey publicKey = getPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqMvvUYyO3naTvlY6dYggLD1SNFepSsr3/MN4RACtGi3HNXV1E/gWGXAufwd9pwzOFHTWJ7m4IHzTe2p1u27fPGmQBoIFL7nrtI1G2XY7vXTMImZDepp4+nB6rDt3L/QhTrAdx73XWWMSQb8HuN1W19xBGokX9E4YUSJiq7QVJmJ2W2HeX3cBdoYcvysIXo0vTrHU6k25blPFaLFuXrR3NGKrEKLJ+v/VNIjHoNVnMO6Y8apPEZ07XafMwkXuqSOkFx0QcJRvLPv3YTdwfRsGpE9KJIt9HWd83Pl/IdvdTNsQDSKHNcz2Nqp5jr5HQJ2Wqcat1msNRlLoNCko5sL1cQIDAQAB");
        RSAPrivateKey privateKey = getPrivateKey("MIICozCCAYsCBgFsb/OhejANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDDApzcHJpbmctYXBpMB4XDTE5MDgwODA2MzcxM1oXDTI5MDgwODA2Mzg1M1owFTETMBEGA1UEAwwKc3ByaW5nLWFwaTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKjL71GMjt52k75WOnWIICw9UjRXqUrK9/zDeEQArRotxzV1dRP4FhlwLn8HfacMzhR01ie5uCB803tqdbtu3zxpkAaCBS+567SNRtl2O710zCJmQ3qaePpweqw7dy/0IU6wHce911ljEkG/B7jdVtfcQRqJF/ROGFEiYqu0FSZidlth3l93AXaGHL8rCF6NL06x1OpNuW5TxWixbl60dzRiqxCiyfr/1TSIx6DVZzDumPGqTxGdO12nzMJF7qkjpBcdEHCUbyz792E3cH0bBqRPSiSLfR1nfNz5fyHb3UzbEA0ihzXM9jaqeY6+R0CdlqnGrdZrDUZS6DQpKObC9XECAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAX3Xo5FgSXPDjJHayCiYTHVJONWvHYZf9RbQI9rD3FZtcZHVqohJ0ZgKUV3F3MuiDvHN4XbEVee3/uj1M2XsVQOD+shBS5m4NykOptXqTlO5OXZy+2c012XofqTLd+3qbClcpfGniEwyiVn71RBIH2vNbV9pml0wUqVGnHXtKFgetRj5LeRIyQ7FKlfWZ+j15j1pPe8/tTxqfPpocgLaqtAqoZTz34z+y/xN7slRCfzfzrFynAdtoKMtop57uBsv91qX8xyCpeF+h4LQJQdUyPZaJCvHoX29Nkvwneu9BD0b4UiWyLxIcI5tepHM+63RMCbkpuRwRHjUP441q8VS8xA==");
        try {
            Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
            JWTVerifier verifier = JWT.require(algorithm)
//                    .withIssuer("auth0")
                    .build(); //Reusable verifier instance
            DecodedJWT jwt = verifier.verify(token);
            System.out.println(1);
        } catch (Exception exception) {
            //Invalid signature/claims
            System.out.println(2);
        }
    }

    public void create() {
        try {
            Algorithm algorithm = Algorithm.HMAC256("secret");
            String token = JWT.create()
                    .withIssuer("auth0")
                    .sign(algorithm);
        } catch (JWTCreationException exception) {
            //Invalid Signing configuration / Couldn't convert Claims.
        }
    }

    */
/**
     * 得到公钥
     *
     * @param publicKey 密钥字符串（经过base64编码）
     * @throws Exception
     *//*

    public static RSAPublicKey getPublicKey(String publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
        //通过X509编码的Key指令获得公钥对象
        KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
        X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(Base64.decodeBase64(publicKey));
        RSAPublicKey key = (RSAPublicKey) keyFactory.generatePublic(x509KeySpec);
        return key;
    }

    */
/**
     * 得到私钥
     *
     * @param privateKey 密钥字符串（经过base64编码）
     * @throws Exception
     *//*

    public static RSAPrivateKey getPrivateKey(String privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
        //通过PKCS#8编码的Key指令获得私钥对象
        KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey));
        RSAPrivateKey key = (RSAPrivateKey) keyFactory.generatePrivate(pkcs8KeySpec);
        return key;
    }
}
*/
